/*
 * @Author: Maverick m14775611609@163.com
 * @Date: 2025-03-09 22:26:02
 * @LastEditors: Maverick m14775611609@163.com
 * @LastEditTime: 2025-03-10 00:48:55
 * @FilePath: /envtest/env.c
 * @Description: 
 * 
 * Copyright (c) 2025 by Maverick, Xiao Bi Software Company ,All Rights Reserved. 
 */
#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<string.h>
#define MINORMASK ((1U<<20)-1)
int main()
{
    char *p=NULL;
    char env_str[4][100]={"LANG","USER","JAVA_HOME","SHELL"};
    //GETENV
    for (size_t i = 0; i < 4; i++)
    {
        /* code */
        p = getenv(env_str[i]);
        if(p!=NULL)
        {
            printf("%s=%s\n",env_str[i],p);
        }
        else
        {
            printf("%s is not exist\n",env_str[i]);
        }
    }
    //PUTENV
    putenv("ABC=abc");
    
    if(p=getenv("ABC"))
    {
        printf("ABC=%s\n",p);
    }
    

    //getallenv
    extern char **environ;
    for (size_t i = 0; environ[i]!=NULL; i++)
    {
        /* code */
        printf("%s\n",environ[i]);
    }
    printf("%d\n",MINORMASK);

    return 0;
}

// maverick@localhost:~/Desktop/pro/code/envtest$ gcc env.c -o env
// maverick@localhost:~/Desktop/pro/code/envtest$ ./env 
// LANG=en_US.UTF-8
// USER=maverick
// JAVA_HOME is not exist
// SHELL=/bin/bash
// ABC=abc